#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>

struct memStruct
{
    /* data */
    int pid;
    char *name; // 进程的第二个参数
};

int main(int argc, char *argv[])
{
    // 创建共享内存 int shmget(key_t key, size_t size,int shmflg);
    int shmid = shmget(0x00000145, sizeof(memStruct), IPC_CREAT | 0666);
    if (shmid == 0)
    {

        // 链接共享内存
        memStruct *ss = nullptr;
        ss = (memStruct *)shmat(shmid, NULL, 0);
        if (ss != (memStruct *)(-1))
        {
            ss->pid = getpid();
            ss->name = argv[1];

            printf("id是什么%d\n", ss->pid);
            printf("id是什么%s\n", ss->name);
        }
        shmdt(ss);
        ss = nullptr;
    }

    return 0;
}